package classesInterface;

import classesBancodeDados.Paciente;
import classesBancodeDados.Responsavel;
import classesJpa.FichaInternamentoJpaController;
import classesJpa.ResponsavelJpaController;
import classesJpa.exceptions.NonexistentEntityException;
import classesJpa.exceptions.PreexistingEntityException;
import classesMiolo.Formatador;
import classesMiolo.MapasFichaInternamento;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

public class TelaFichaInternamento2 extends javax.swing.JFrame {

    /**
     * Creates new form FichaInternamento2
     */
    private TelaFichaInternamento2() {
        initComponents();
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    }
    
    private static TelaFichaInternamento2 uniqueInstance;
    
    public static TelaFichaInternamento2 getInstance(){
        if(uniqueInstance == null){
            uniqueInstance = new TelaFichaInternamento2();
        }
        return uniqueInstance;
    }
    
    public void limpaCampos(){
        campoCPFSaida.setText("");
        campoCpf.setText("");
        campoCpfR1.setText("");
        campoCpfR2.setText("");
        campoData.setText("");
        campoDataSaida.setText("");
        campoHoraSaida.setText("");
        campoIdent.setText("");
        campoIdentR1.setText("");
        campoIdentR2.setText("");
        campoIdentSaida.setText("");
        campoMotivo.setText("");
        campoNome.setText("");
        campoNomeResp1.setText("");
        campoNomeResp2.setText("");
        campoPaciente.setText("");
        campoRelacao.setText("");
        campoTestemunhas.setText("");
    }
    
    public void turnEditable(boolean editable){
        botaoSalvar.setEnabled(editable);
        campoCPFSaida.setEditable(false);
        campoCpf.setEditable(false);
        campoCpfR1.setEditable(false);
        campoCpfR2.setEditable(editable);
        campoData.setEditable(editable);
        campoDataSaida.setEditable(editable);
        campoHoraSaida.setEditable(editable);
        campoIdent.setEditable(false);
        campoIdentR1.setEditable(false);
        campoIdentR2.setEditable(editable);
        campoIdentSaida.setEditable(false);
        campoMotivo.setEditable(editable);
        campoNome.setEditable(false);
        campoNomeResp1.setEditable(false);
        campoNomeResp2.setEditable(editable);
        campoPaciente.setEditable(false);
        campoRelacao.setEditable(editable);
        campoTestemunhas.setEditable(editable);        
    }
    
    private void salvar(){
        ficha.setDataInter(this.campoData.getText());
        ficha.setDataAlta(this.campoDataSaida.getText());
        ficha.setHoraInter(this.campoHoraSaida.getText());
        MapasFichaInternamento mfi = MapasFichaInternamento.getInstance();
        ficha.setMotivoAlta(mfi.getMotivoAlta().get(this.campoMotivo.getText()));
        ficha.setTestemunhas(this.campoTestemunhas.getText());
        ficha.setParentesco(this.campoRelacao.getText());
        ficha.setCpfResp2(this.campoCpfR2.getText());
        
        ResponsavelJpaController jpa = new ResponsavelJpaController();
        Responsavel resp = new Responsavel();
        resp.setCpf(campoCpfR2.getText());
        resp.setEndereco("");
        resp.setIdent(campoIdentR2.getText());
        resp.setNome(campoNomeResp2.getText());
        resp.setTelefone("");
        try {
            jpa.edit(resp);
        } catch (NonexistentEntityException ex) {
            try {
                jpa.create(resp);
            } catch (PreexistingEntityException ex1) {
                System.err.println("Isto é impossível!!!");
            } catch (Exception ex1) {
                JOptionPane.showMessageDialog(null, "Erro na comunicação com o Banco de Dados", "ERRO", JOptionPane.ERROR_MESSAGE);
            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, "Erro na comunicação com o Banco de Dados", "ERRO", JOptionPane.ERROR_MESSAGE);
        }
        
        FichaInternamentoJpaController fic = new FichaInternamentoJpaController();
        try {
            fic.edit(ficha);
        } catch (NonexistentEntityException ex) {
            Logger.getLogger(TelaFichaInternamento2.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(TelaFichaInternamento2.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public void preencherCampos(Paciente p, Responsavel r1, classesBancodeDados.FichaInternamento fi){
        this.campoNome.setText(p.getNome());
        this.campoData.setText(fi.getDataInter());
        this.campoNomeResp1.setText(r1.getNome());
        this.campoIdentR1.setText(r1.getIdent());
        this.campoCpfR1.setText(r1.getCpf());
        this.campoPaciente.setText(p.getNome());
        this.campoRelacao.setText(fi.getParentesco());
        this.campoDataSaida.setText(fi.getDataAlta());
        this.campoHoraSaida.setText(fi.getHoraInter());
        this.campoIdentSaida.setText(p.getIdentidade());
        this.campoCPFSaida.setText(p.getCpf());
        this.campoTestemunhas.setText(fi.getTestemunhas());
        this.campoMotivo.setText(fi.getMotivoPedido());
        ResponsavelJpaController jpa = new ResponsavelJpaController();
        Responsavel r2 = jpa.findResponsavel(ficha.getCpfResp2());
        if(r2 == null){
            this.campoNomeResp2.setText("");
            this.campoIdentR2.setText("");
            this.campoCpfR2.setText("");
            return;
        }
        this.campoNomeResp2.setText(r2.getNome());
        this.campoIdentR2.setText(r2.getIdent());
        this.campoCpfR2.setText(r2.getCpf());
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel2 = new javax.swing.JLabel();
        campoNome = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        campoData = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        campoNomeResp1 = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        campoIdentR1 = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        campoCpfR1 = new javax.swing.JTextField();
        jSeparator2 = new javax.swing.JSeparator();
        jLabel10 = new javax.swing.JLabel();
        campoNomeResp2 = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        campoIdentR2 = new javax.swing.JTextField();
        campoCpfR2 = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        jSeparator3 = new javax.swing.JSeparator();
        jLabel13 = new javax.swing.JLabel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        campoIdent = new javax.swing.JTextField();
        jLabel16 = new javax.swing.JLabel();
        campoCpf = new javax.swing.JTextField();
        jSeparator4 = new javax.swing.JSeparator();
        jLabel17 = new javax.swing.JLabel();
        campoPaciente = new javax.swing.JTextField();
        jLabel18 = new javax.swing.JLabel();
        campoRelacao = new javax.swing.JTextField();
        jLabel19 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        jLabel21 = new javax.swing.JLabel();
        campoDataSaida = new javax.swing.JTextField();
        jLabel22 = new javax.swing.JLabel();
        campoHoraSaida = new javax.swing.JTextField();
        jLabel23 = new javax.swing.JLabel();
        campoIdentSaida = new javax.swing.JTextField();
        jLabel24 = new javax.swing.JLabel();
        campoCPFSaida = new javax.swing.JTextField();
        jLabel25 = new javax.swing.JLabel();
        campoTestemunhas = new javax.swing.JTextField();
        jLabel26 = new javax.swing.JLabel();
        campoMotivo = new javax.swing.JTextField();
        botaoSalvar = new javax.swing.JButton();
        botaoAnterior = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });

        jLabel1.setText("Autorização para internação e tratamento");

        jLabel2.setText("Autorizo a internação de");

        jLabel3.setText("neste frenocômio, podendo ser submetido aos tratamento clínicos que se fizerem necessários, bem");

        jLabel4.setText("como a participação nas atividades hospitalares que busquem a melhoria do quadro apresentado.");

        jLabel5.setText("Data:");

        campoData.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                campoDataKeyPressed(evt);
            }
        });

        jLabel6.setText("Responsáveis pelo paciente para visitá-lo");

        jLabel7.setText("Nome:");

        jLabel8.setText("Nº Identidade:");

        jLabel9.setText("Nº do CPF:");

        campoCpfR1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                campoCpfR1KeyPressed(evt);
            }
        });

        jLabel10.setText("Nº Identidade:");

        jLabel11.setText("Nº do CPF:");

        campoCpfR2.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                campoCpfR2KeyPressed(evt);
            }
        });

        jLabel12.setText("Nome:");

        jLabel13.setText("Normas de Alta a Pedido:");

        jLabel14.setText("Recebi no ato do internamento as \"Normas e Rotinas\" deste Complexo Psiquiátrico Juliano Moreira");

        jLabel15.setText("Nº Identidade:");

        jLabel16.setText("CPF:");

        campoCpf.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                campoCpfKeyPressed(evt);
            }
        });

        jLabel17.setText("Ao meu pedido, retiro o paciente");

        jLabel18.setText("meu");

        jLabel19.setText(", deste Frenocômio, sem alta médica e isento os médicos e o Hospital de qualquer responsabilidade");

        jLabel20.setText("pelos danos que este ato possa provocar, assumindo inteira responsabilidade sobre ele.");

        jLabel21.setText("Data:");

        campoDataSaida.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                campoDataSaidaKeyPressed(evt);
            }
        });

        jLabel22.setText("Hora:");

        campoHoraSaida.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                campoHoraSaidaKeyPressed(evt);
            }
        });

        jLabel23.setText("Nº Identidade:");

        jLabel24.setText("Nº CPF:");

        campoCPFSaida.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                campoCPFSaidaKeyPressed(evt);
            }
        });

        jLabel25.setText("Testemunhas:");

        jLabel26.setText("Motivo do Pedido:");

        botaoSalvar.setText("Salvar");
        botaoSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoSalvarActionPerformed(evt);
            }
        });

        botaoAnterior.setText("< Anterior");
        botaoAnterior.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botaoAnteriorActionPerformed(evt);
            }
        });

        jButton3.setText("Cancelar");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jSeparator3)
                            .addComponent(jSeparator2)
                            .addComponent(jSeparator1)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(campoNome))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel7)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(campoNomeResp1))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel8)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(campoIdentR1, javax.swing.GroupLayout.PREFERRED_SIZE, 263, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel9)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(campoCpfR1))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel12)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(campoNomeResp2))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel10)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(campoIdentR2, javax.swing.GroupLayout.PREFERRED_SIZE, 263, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel11)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(campoCpfR2))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel17)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(campoPaciente))
                            .addComponent(jLabel1)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(campoData, javax.swing.GroupLayout.PREFERRED_SIZE, 178, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jLabel6)
                            .addComponent(jLabel13)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel15)
                                .addGap(3, 3, 3)
                                .addComponent(campoIdent, javax.swing.GroupLayout.PREFERRED_SIZE, 176, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel16)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(campoCpf, javax.swing.GroupLayout.PREFERRED_SIZE, 234, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                .addComponent(jSeparator4, javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel14, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addComponent(jLabel20)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel21)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(campoDataSaida, javax.swing.GroupLayout.PREFERRED_SIZE, 183, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel22)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(campoHoraSaida, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel23)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(campoIdentSaida, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel24)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(campoCPFSaida, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jLabel25)
                                .addGap(18, 18, 18)
                                .addComponent(campoTestemunhas)))
                        .addContainerGap())
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel18)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(campoRelacao)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel19)
                        .addGap(29, 29, 29))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel26)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(campoMotivo)
                        .addContainerGap())))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(botaoAnterior)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(botaoSalvar)
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(campoNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(campoData, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(campoNomeResp1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(campoIdentR1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9)
                    .addComponent(campoCpfR1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(campoNomeResp2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(campoIdentR2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11)
                    .addComponent(campoCpfR2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel13)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel14)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel15)
                    .addComponent(campoIdent, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel16)
                    .addComponent(campoCpf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator4, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel17)
                    .addComponent(campoPaciente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel18)
                    .addComponent(campoRelacao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel19))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel20)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel21)
                    .addComponent(campoDataSaida, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel22)
                    .addComponent(campoHoraSaida, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel23)
                    .addComponent(campoIdentSaida, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel24)
                    .addComponent(campoCPFSaida, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel25)
                    .addComponent(campoTestemunhas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel26)
                    .addComponent(campoMotivo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 8, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(botaoSalvar)
                    .addComponent(botaoAnterior)
                    .addComponent(jButton3)))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void campoHoraSaidaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_campoHoraSaidaKeyPressed
        if(evt.getKeyChar() != '\b'){
            campoHoraSaida.setText(Formatador.formataHora(campoHoraSaida.getText()));
        }
    }//GEN-LAST:event_campoHoraSaidaKeyPressed

    private void campoDataKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_campoDataKeyPressed
        if(evt.getKeyChar() != '\b'){
            campoData.setText(Formatador.formataData(campoData.getText()));
        }
    }//GEN-LAST:event_campoDataKeyPressed

    private void botaoSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoSalvarActionPerformed
        salvar();
    }//GEN-LAST:event_botaoSalvarActionPerformed

    private void botaoAnteriorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botaoAnteriorActionPerformed
        TelaFichaInternamento.getInstance().setVisible(true);
        setVisible(false);
    }//GEN-LAST:event_botaoAnteriorActionPerformed

    private void campoCpfR1KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_campoCpfR1KeyPressed
        if(evt.getKeyChar() != '\b'){
            campoCpfR1.setText(Formatador.formataCPF(campoCpfR1.getText()));
        }
    }//GEN-LAST:event_campoCpfR1KeyPressed

    private void campoCpfR2KeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_campoCpfR2KeyPressed
        if(evt.getKeyChar() != '\b'){
            campoCpfR2.setText(Formatador.formataCPF(campoCpfR2.getText()));
        }
    }//GEN-LAST:event_campoCpfR2KeyPressed

    private void campoCpfKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_campoCpfKeyPressed
        if(evt.getKeyChar() != '\b'){
            campoCpf.setText(Formatador.formataCPF(campoCpf.getText()));
        }
    }//GEN-LAST:event_campoCpfKeyPressed

    private void campoDataSaidaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_campoDataSaidaKeyPressed
        if(evt.getKeyChar() != '\b'){
            campoDataSaida.setText(Formatador.formataData(campoDataSaida.getText()));
        }
    }//GEN-LAST:event_campoDataSaidaKeyPressed

    private void campoCPFSaidaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_campoCPFSaidaKeyPressed
        if(evt.getKeyChar() != '\b'){
            campoCPFSaida.setText(Formatador.formataCPF(campoCPFSaida.getText()));
        }
    }//GEN-LAST:event_campoCPFSaidaKeyPressed

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        TelaFichaInternamento.getInstance().limpaCampos();
        TelaFichaInternamento2.getInstance().limpaCampos();
        setVisible(false);
    }//GEN-LAST:event_jButton3ActionPerformed

    private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
        TelaFichaInternamento.getInstance().limpaCampos();
        TelaFichaInternamento2.getInstance().limpaCampos();
    }//GEN-LAST:event_formWindowClosed

    public classesBancodeDados.FichaInternamento getFicha() {
        return ficha;
    }

    public void setFicha(classesBancodeDados.FichaInternamento ficha) {
        this.ficha = ficha;
    }   
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(TelaFichaInternamento2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(TelaFichaInternamento2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(TelaFichaInternamento2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(TelaFichaInternamento2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                TelaFichaInternamento2.getInstance().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botaoAnterior;
    private javax.swing.JButton botaoSalvar;
    private javax.swing.JTextField campoCPFSaida;
    private javax.swing.JTextField campoCpf;
    private javax.swing.JTextField campoCpfR1;
    private javax.swing.JTextField campoCpfR2;
    private javax.swing.JTextField campoData;
    private javax.swing.JTextField campoDataSaida;
    private javax.swing.JTextField campoHoraSaida;
    private javax.swing.JTextField campoIdent;
    private javax.swing.JTextField campoIdentR1;
    private javax.swing.JTextField campoIdentR2;
    private javax.swing.JTextField campoIdentSaida;
    private javax.swing.JTextField campoMotivo;
    private javax.swing.JTextField campoNome;
    private javax.swing.JTextField campoNomeResp1;
    private javax.swing.JTextField campoNomeResp2;
    private javax.swing.JTextField campoPaciente;
    private javax.swing.JTextField campoRelacao;
    private javax.swing.JTextField campoTestemunhas;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JSeparator jSeparator4;
    // End of variables declaration//GEN-END:variables
    private classesBancodeDados.FichaInternamento ficha;
}
